import api from '@/api';

export default {
  namespace: 'sign',

  state: {
    signStatus: 0,
    groupList: []
  },

  effects: {
    *querySignStatus({ payload }, { call, put }) {
      const response = yield call(api.sign.signStatus, payload)
      if (response.errorCode === 0) {
        yield put({
          type: 'saveSignStatus',
          payload: response.data
        })
      }
    },
    *signIn({ payload }, { call }) {
      return yield call(api.sign.signIn, payload)
    },
    *checkLast({ payload }, { call }) {
      return yield call(api.sign.checkLast, payload)
    },
    *signOut({ payload }, { call }) {
      return yield call(api.sign.signOut, payload)
    },
    *queryGroupSignUser({ payload }, { call }) {
      return yield call(api.sign.queryGroupSignUser, payload)
    },
    *queryGroupAllUser({ payload }, { call }) {
      return yield call(api.sign.queryGroupAllUser, payload)
    },
    *queryGroupByUserID({ payload }, { call }) {
      return yield call(api.sign.queryGroupByUserID, payload)
    },
    *queryGroup({ payload }, { call, put }) {
      const response = yield call(api.sign.queryGroup, payload)
      console.log(response)
      if (response && response.errorCode === 0) {
        yield put({
          type: 'saveGroup',
          payload: response.data
        })
      }
    },

  },

  reducers: {
    saveSignStatus(state, { payload }) {
      return {
        ...state,
        signStatus: payload
      };
    },
    saveGroup(state, { payload }) {
      console.log(payload)
      return {
        ...state,
        groupList: payload
      };
    },
  },
};
